package bjtu.cit.bookshop.service.impl;

import bjtu.cit.bookshop.daos.UserMapper;
import bjtu.cit.bookshop.entities.User;
import bjtu.cit.bookshop.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by jia19 on 2015/9/20.
 */
@Service("userService")
public class UserServiceImpl implements IUserService {

    @Resource
    private UserMapper userMapper;//数据库操作接口

    @Override
    public User getUserById(int userId) {
        return this.userMapper.selectByPrimaryKey(userId);
    }

    @Override
    public User getUserByUserName(String username) {
        return this.userMapper.selectByUsername(username);
    }

    @Override
    public int createAUser(User user) {
        user.setId(null);
        return this.userMapper.insertSelective(user);
    }

    @Override
    public int updateUserInfo(User user) {
        return this.userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int deleteUserById(int id) {
        return this.userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<User> getUserList() {
        return this.userMapper.selectUserList();
    }
}
